// functionPage/pages/news/noticeNews/noticeNews.js
import Http from '../../../../utils/http.js';
import { getTimePart } from '../../../../utils/util.js';
const http = new Http();
const app = getApp();
Page({
    /**
     * 页面的初始数据
     */
    data: {
        arrIndex: '',
        contentList: [],
        pageNum: 0,
        loading: true,
        loadingAll: false,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getNewsList();
    },
    onHide: function () {
        if (this.data.contentList[this.data.arrIndex].readflg == '00') {
            let item = 'contentList[' + this.data.arrIndex + '].readflg';
            this.setData({
                [item]: '01',
            });
        }
    },
    getIndex(e) {
        this.setData({
            arrIndex: e.currentTarget.dataset.index,
        });
    },
    // 获取消息列表
    getNewsList() {
        if (!this.data.loadingAll) {
            this.setData({
                pageNum: this.data.pageNum + 1,
                loading: true,
                loadingAll: false,
            });
            let data = {
                authId: app.globalData.authId,
                origintype: '02',
                pageNo: this.data.pageNum,
                pageSize: 20,
            };
            http.getRequest('cjMap/getRelatedMsgList', data).then((res) => {
                if (res.status == 0) {
                    res.data.map((item) => {
                        item.createtime = getTimePart(item.createtime).format;
                        item.myself = item.createuid == app.globalData.uid;
                        this.data.contentList.push(item);
                    });
                    this.setData({
                        contentList: this.data.contentList,
                        loading: false,
                    });

                    if (res.pager.currentPage >= res.pager.totalPages) {
                        this.setData({
                            loadingAll: true,
                        });
                    }
                } else {
                    this.setData({
                        loadingAll: true,
                        loading: false,
                    });
                }
            });
        }
    },
});
